package com.itheima.springboot_24_mq.service.impl.kafka;

import com.itheima.springboot_24_mq.service.MessageService;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

@Service//有了service,springboot才能自动捕获到这个类
public class MessageServiceKafkaImpl implements MessageService {
    @Autowired
    private KafkaTemplate kafkaTemplate;
    @Override
    public void sendMessage(String id) { //把id放入消息队列
        System.out.println("把消息放入到队列:"+id);
        kafkaTemplate.send("itheima",id);//参数解释:队列名,要手动创建;要插入到队列的消息是啥
        kafkaTemplate.send("itheima2",id);//参数解释:队列名,要手动创建;要插入到队列的消息是啥
        kafkaTemplate.send("itheima3",id);//参数解释:队列名,要手动创建;要插入到队列的消息是啥
        kafkaTemplate.send("itheima4",id);//参数解释:队列名,要手动创建;要插入到队列的消息是啥
    }

    @Override
    public String doMessage() { //从队列中获取id,发送短信
//        String id="消息id为空";
//        if(msgList.size()>0){
//            id=msgList.remove(0);
//            System.out.println("从队列里取出一个id,发送短信");
//        }
        return null;
    }
}
